<template>
	<view class="content">
		<view class="list-container">
			<view class="shenhe-list clear edit_con">
				<text class="left input_text" >
					原密码
				</text>
				<input type="password" placeholder="请输入原密码" v-model="old_pass" placeholder-style="font-size:30rpx;color:#999999" class="no_border_input left" />
			</view>
			<view class="shenhe-list clear edit_con">
				<text class="left input_text" >
				   新密码
				</text>
				<input type="password" placeholder="请输入新密码" v-model="password" placeholder-style="font-size:30rpx;color:#999999" class="no_border_input left" />
			</view>
			<view class="shenhe-list clear edit_con">
				<text class="left input_text" >
					确认密码
				</text>
				<input type="password" placeholder="请输入确认密码" v-model="password_confirm" placeholder-style="font-size:30rpx;color:#999999" class="no_border_input left" />
			</view>	
		</view>	
			
		<button class="big_button baocun-btn" @tap="save()" style="background:#FFFFFF;border: 1px solid #1e99ff;color: #1e99ff;">
			保存
		</button>
	</view>
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	export default {
		data() {
			return {
				user:{},//用户登录信息
				password:"",//新密码
				password_confirm:"",//确认密码
				old_pass:"",//确认密码
			}
		},
		onLoad() {
	        this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}	
		},
		methods: {
			save(){//获取客户端首页信息
			    let $password=/^[0-9a-zA-Z]{6,18}$/g;
			    let $password2=/^[0-9a-zA-Z]{6,18}$/g;
			    let $password3=/^[0-9a-zA-Z]{6,18}$/g;
			    if(this.old_pass==""||this.old_pass==null){
			    	uni.showModal({
			    		showCancel:false,
			    		content:"请填写旧密码"
			    	})
			    	return false;
			    }else if(!$password.test(this.old_pass)){
			    	uni.showModal({
			    		showCancel:false,
			    		content:"旧密码是6~18位的数字或字母"
			    	})
			    	return false;
			    }    
				if(this.password==""||this.password==null){
			    	uni.showModal({
			    		showCancel:false,
			    		content:"请填写新密码"
			    	})
			    	return false;
			    }
				else if(!$password2.test(this.password)){
			    	uni.showModal({
			    		showCancel:false,
			    		content:"新密码是6~18位的数字或字母"
			    	})
			    	return false;
			    }   
				if(this.password_confirm==""||this.password_confirm==null){
			    	uni.showModal({
			    		showCancel:false,
			    		content:"请填写确认密码"
			    	})
			    	return false;
			    }
				else if(!$password3.test(this.password_confirm)){
					console.log(this.password_confirm)
			    	uni.showModal({
			    		showCancel:false,
			    		content:"确认密码是6~18位的数字或字母"
			    	})
			    	return false;
			    }
				if(this.password_confirm!=this.password){
					uni.showModal({
						showCancel:false,
						content:"两次密码不一致"
					})
					return false;
				}
				uni.request({
					url: httpPath.filePath+'/api.php/index/member/edit_password/',
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id,password:this.password,password_confirm:this.password_confirm,old_pass:this.old_pass},
					success: (res) => {
						if(res.data.code=="200"){
							uni.showModal({
								showCancel:false,
								content:"设置成功"
							})
							uni.navigateBack()
						}else{
							uni.showModal({
								content:res.data.message,
								showCancel:false
							})
						}
						   
					}
				});
				
			}
	      
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
	page{background: #FFFFFF;}
	.hetong-list image{width: 100%;height: 100%;}
	.shenhe-text1{line-height: 70rpx!important;color: #323232;}
	.edit_con{padding: 10px 0px;}
</style>
